//
//  MineCancelAccountVC.m
//  Peso Guide
//
//  Created by macbook on 2025/6/12.
//

#import "MineCancelAccountVC.h"
#import "CancelAccountAlertView.h"

@interface MineCancelAccountVC ()

@property (nonatomic, strong) UIImageView *backImg;
@property (nonatomic, strong) UIScrollView *bgScrollView;
@property (nonatomic, strong) UIButton *agreeButton;

@end

@implementation MineCancelAccountVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navView.backgroundColor = [UIColor clearColor];
    self.titleLabel.text = [Lang set:@"Account cancelation"];
    
    _backImg = [PesoKit createImageViewWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight) imageNamed:@"bg_mine_cancel"];
    _backImg.userInteractionEnabled = YES;
    [self.view addSubview:_backImg];
    
    _bgScrollView = [PesoKit createScrollViewWithFrame:CGRectMake(0, kStarBarHeight, KScreenWidth, KScreenHeight-kStarBarHeight) backGroundColor:[UIColor clearColor]];
    _bgScrollView.showsVerticalScrollIndicator = NO;
    _bgScrollView.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:_bgScrollView];
    
    UIView *whiteView = [PesoKit createViewWithFrame:CGRectMake(21, 20, KScreenWidth-42, 247) backGroundColor:ColorHex(@"#FFFFFF")];
    whiteView.clipsToBounds = YES;
    whiteView.layer.cornerRadius = 15.0f;
    [_bgScrollView addSubview:whiteView];
    
    UIView *bottomView = [PesoKit createViewWithFrame:CGRectMake(21, whiteView.bottom+16, KScreenWidth-42, 374) backGroundColor:ColorHex(@"#FFFFFF")];
    bottomView.clipsToBounds = YES;
    bottomView.layer.cornerRadius = 15.0f;
    [_bgScrollView addSubview:bottomView];
    
    UILabel *messageLabel1 = [PesoKit createLabelWithFrame:CGRectMake(32, 12, whiteView.width-32*2, 36) backGroundColor:[UIColor whiteColor] text:[Lang set:@"Please carefully read the agreement belowto confirmcancellation"] textColor:ColorHex(@"#0E1D31") font:FONT(FontWeightStyleRegular, 12)];
    messageLabel1.textAlignment = NSTextAlignmentCenter;
    messageLabel1.numberOfLines = 0;
    [whiteView addSubview:messageLabel1];
    
    UIImageView *warringImg = [PesoKit createImageViewWithFrame:CGRectMake((whiteView.width-167)/2.0, 57, 167, 167) imageNamed:@"ic_mine_cancel_warring"];
    [whiteView addSubview:warringImg];
    
    
    UILabel *titleLabel = [PesoKit createLabelWithFrame:CGRectMake(10, 16, bottomView.width-20, 20) backGroundColor:[UIColor whiteColor] text:[Lang set:@"Pay attention to"] textColor:ColorHex(@"#0E1D31") font:FONT(FontWeightStyleMedium, 14)];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [bottomView addSubview:titleLabel];
    
    UILabel *messageLabel2 = [PesoKit createLabelWithFrame:CGRectMake(10, 52, bottomView.width-20, 168) backGroundColor:[UIColor whiteColor] text:[Lang set:@"The account cannot be restored after cancellation. In order to ensure the security of your account, please confirm that the account-related services have been handled correctly before the application and pay attention to the following provisions"] textColor:ColorHex(@"#0E1D31") font:FONT(FontWeightStyleRegular, 17)];
    messageLabel2.textAlignment = NSTextAlignmentCenter;
    messageLabel2.numberOfLines = 0;
    [bottomView addSubview:messageLabel2];
    
    [messageLabel2 sizeToFit];
    
    UILabel *messageLabel3 = [PesoKit createLabelWithFrame:CGRectMake(10, messageLabel2.bottom+5, bottomView.width-20, 22) backGroundColor:[UIColor whiteColor] text:[Lang set:@"All loans have been repaid"] textColor:ColorHex(@"#FF4D4D") font:FONT(FontWeightStyleMedium, 16)];
    messageLabel3.textAlignment = NSTextAlignmentCenter;
    [bottomView addSubview:messageLabel3];
    
    
    UILabel *agreeLabel = [PesoKit createLabelWithFrame:CGRectMake(0, bottomView.height-81-17, bottomView.width-20, 17) backGroundColor:[UIColor whiteColor] text:[Lang set:@"I have read and agreed to the above"] textColor:ColorHex(@"#0E1D31") font:FONT(FontWeightStyleRegular, 12)];
    [bottomView addSubview:agreeLabel];
    
    CGSize agreeSize = [AppTools sizeWithText:agreeLabel.text font:FONT(FontWeightStyleRegular, 12) maxSize:CGSizeMake(KScreenWidth, 17)];
    agreeLabel.left = (bottomView.width-agreeSize.width)/2.0;
    
    
    _agreeButton = [[UIButton alloc] initWithFrame:CGRectMake(agreeLabel.left-5-16, bottomView.height-81-16.5, 16, 16)];
    _agreeButton.selected = NO;
    [_agreeButton addTarget:self action:@selector(agreeButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [_agreeButton setBackgroundImage:[UIImage imageNamed:@"ic_login_agree"] forState:0];
    [bottomView addSubview:_agreeButton];
    
    UIButton *loanButton = [PesoKit createButtonWithFrame:CGRectMake((bottomView.width-214)/2.0, bottomView.height-21-44, 214, 44) backGroundColor:[UIColor clearColor] title:[Lang set:@"Account cancellation"] titleColor:ColorHex(@"#FFFFFF") font:FONT(FontWeightStyleMedium, 18)];
    [loanButton setBackgroundImage:[UIImage imageNamed:@"bg_mine_cancel_button"] forState:0];
    [loanButton addTarget:self action:@selector(loanButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [bottomView addSubview:loanButton];
    
    _bgScrollView.contentSize = CGSizeMake(KScreenWidth, 247+374+16+20+kSafeBottomHeight+20);
    [self.view addSubview:self.navView];
}

- (void)loanButtonClick {
    
    if (_agreeButton.isSelected == NO) {
        
        [SVProgressHUD showErrorWithStatus:[Lang set:@"Please agree to the above"]];
        [SVProgressHUD dismissWithDelay:3.0f];

        return;
    }
    
    CancelAccountAlertView *alertView = [[CancelAccountAlertView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
    [self.view addSubview:alertView];
    
//    [[AWHttpService service] getWithUrl:@"/trains/unnested" params:@{} succ:^(id  _Nonnull responseObject) {
//        if (SUCCESS) {
//            NSString *order = [NSString stringWithFormat:@"%@",[responseObject safeObjectForKey:@"order"]];
//            [SVProgressHUD showSuccessWithStatus:order];
//            
//            [self performSelector:@selector(tologin111) withObject:nil afterDelay:2];
//        }
//    } fail:^(NSInteger errorType, id  _Nonnull error) {
//        
//    }];
}

- (void)tologin111 {
    [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"user_token"];
    
    [AppTools getCurrentVC].navigationController.tabBarController.selectedIndex = 0;
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)agreeButtonClick:(UIButton *)sender {
    if (sender.isSelected == NO) {
        sender.selected = YES;
        [_agreeButton setBackgroundImage:[UIImage imageNamed:@"ic_login_agree_select"] forState:0];
    }else {
        sender.selected = NO;
        [_agreeButton setBackgroundImage:[UIImage imageNamed:@"ic_login_agree"] forState:0];
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
